//
//  NSString+Encrypt.m
//  iOSTools
//
//  Created by BaizYi on 2018/12/28.
//  Copyright © 2018 YJY. All rights reserved.
//

#import "NSString+Encrypt.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (Encrypt)

-(NSString *)md5String{
    return [self bzy_encryptMD5];
}

-(NSString *)bzy_encryptMD5{
    
    const char *cStr = self.UTF8String;
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    CC_MD5( cStr, (CC_LONG)strlen(cStr), digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++){
        [result appendFormat:@"%02x", digest[i]];
    }
    
    return result;
}

@end
